from typing import Union, Optional

from models import execute_sort, execute


async def get_goods_record(spu_ids) -> list:
    res = await execute_sort('select id, title, price, img from good where id = %s', tuple(spu_ids))
    return res


async def query_goods_is_exist(spu_id):
    if not isinstance(spu_id, list):
        _, res = await execute('select id from good where id  = %s', (spu_id,))
        return res
    else:
        _, res = await execute('select id from good where id in (%s)' % ','.join(['%s'] * len(spu_id)), tuple(spu_id))
        return res